import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';

import service from '@/utils/request';

export interface LoginData {
  username: string;
  password: string;
  code: string;
}
export interface LoginRes {
  token: string;
}

export function doLogin(data: LoginData) {
  return service.request({
    method: 'POST',
    url: '/login',
    headers: {
      onLogin: true,
    },
    data,
  });
}
// 获取用户信息
export function getUserInfo() {
  return service.request({
    method: 'get',
    url: '/getInfo',
  });
}
// 获取验证码
export function getCaptchaImage() {
  return service.request({
    method: 'get',
    url: '/captchaImage',
    headers: {
      onLogin: true,
    },
  });
}

export function logout() {
  return service.request({
    method: 'get',
    url: '/logout',
  });
}

export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/api/user/menu');
}
